<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./site/public/_pre.php, $Author:  $ */

if ( !isset($_POST['xajax']) )
{
	$oLang = &App::getLanguage();
	$oTpl = &App::getTemplate();
	$oReq = &App::getRequest();
	
	if ( $sGetLanguage = $oReq->getInt('guest_language') )
	{
		$oLang->setGuestLang($sGetLanguage);
		header("Location: ". strip_tags($oReq->get('return')) ."");
		exit;
	}

	//get current user
	$oSrvSec = &App::getModuleService('Account', 'Security');

	$oBanService = &App::getModuleService('Site', 'Ban');
	/* @var $oBanService PhpFox_Mod_Site_ServiceBan */
	$oBanService->checkIPBan();

	$sPageName = App::getPageName();
	$sFirstPart = '';
	$sFirstPart = substr($sPageName, 0, strpos($sPageName, '.'));
	if (!$sFirstPart && $sPageName)
	{
	    $sFirstPart = $sPageName;
	}

	if (App::getSetting('site_shutdown') 
		&& $sPageName != 'public.login'
		&& $sPageName != 'public.contact-us'
		&& $sPageName != 'public.randimagesite'
		&& $sPageName != 'public.randimage'
		&& $sPageName != 'public.under-construction')
	{
	    if (!$oSrvSec->isAdmin())
	    {
	        if (1 == App::getSetting('allow_staff_view_shutdowned') && $oSrvSec->isStaff())
	        {

	        }
	        else
	        {
	            if ($oSrvSec->getCurrentUserLogin())
	            {
	                $oSrvSec->logout();
	                App::gotoUrl('public.under-construction', array(), App::format('Mod_Admin.login_closed'), true);
	            }
	            App::gotoUrl('public.under-construction');
	        }
	    }
	}
	
    if (App::getParam('bVerifyUserSession') && $sPageName != 'public.logout' && (isset($_SESSION['Mod_Account']['by_admin']) && !$_SESSION['Mod_Account']['by_admin']))
	{
		if (isset($_SESSION['phpFox']['sRandId']) && ($_SESSION['phpFox']['sRandId'] != (md5(App::getUser('login') . md5(App::getUser('user'))))))
		{
			$oSrvSec->logout();
			App::gotoUrl('public.logout', array('completed' => 'true', 'multi' => 'true'));
		}
		else 
		{
			$_SESSION['phpFox']['sRandId'] = md5(App::getUser('login') . md5(App::getUser('user')));
		}
	}

	/* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
	$oCurrUser = $oSrvSec->getCurrentUser();

	// add logs
	$oSrvLog = App::getModuleService('Log', 'Log');
	/* @var $oSrvLog PhpFox_Mod_Log_ServiceLog */
	$oSrvLog->addSiteSession($oCurrUser);

	//add page view record
	$aParts = explode('.', App::getPageName());
	if ($oCurrUser && (count($aParts) > 1))
	{
	    $sPage = $aParts[1];
	    $oSrvLog->addPageView($sPage, $oCurrUser);
	}

	$sMeta = "";
	if ( $sExtraMeta = $oReq->get('title') )
	{
		$sExtraMeta = str_replace(array("-","_")," ",$sExtraMeta);
		$sExtraMeta = str_replace('"', '&quot;', $sExtraMeta);
		$sMeta = strip_tags($sExtraMeta);
	}

	$oTpl->assignSrc(array(
		'sUrl'           => $oUrl->getUrl(),
		'sSiteName'      => App::getSetting('site_name'),
		'sSiteTitle'     => App::getSetting('site_title'),
		'bShoutbox'      => App::getSetting('show_shoutbox'),
		'bHideHeader' => true,
    	'sLogoFile'      => App::getSetting('default_logo_name'),
    	'sKeywords'      => $sMeta . phpFoXPlugins::call_phpfox_function('meta_tags') . App::getSetting('meta_keywords'),
    	'bRemoveIm'      => App::pluginInstalled(App::getParam('plugin.im.name')),
    	'bRemoveChat'    => false,
    	'sDescr'         => App::getSetting('meta_description'),
    	'sPathTransJs'   => App::makeJSPathTranslatedValue(),
		'plugin_main_links' => phpFoXPlugins::create_main_links(),
		'plugin_bottom_links' => phpFoXPlugins::create_bottom_links(),
		'plugin_header' => phpFoXPlugins::create_header(),
		'sChatUrl' => App::getParam('plugin.chat.url')
	));

	$oTpl->assign(array(
		'aCurrUser' => ($oCurrUser ? $oCurrUser->aData : false),
		'oCurrUser' => ($oCurrUser ? $oCurrUser : null),
		'bForumOn'  => !App::getSetting('section_forum'),
		'bShutDown' => App::getSetting('site_shutdown'),
		'bAllowHtml' => App::getSetting('allow_html'),
		'bMusicCheck' => $oSrvSec->checkAccess('music','',false),
		'aLanguages' => App::getUser('id') == "" ? $oLang->getLanguages() : '',
		'bAllowLangPack' => App::getSetting('allow_change_lang'),
		'sGuestLang' => isset($_COOKIE['guest_lang']) ? $_COOKIE['guest_lang'] : ''
	));
}

?>